package com.pioneer.web.book.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pioneer.web.book.domain.Book;
import com.pioneer.web.book.domain.Category;
import com.pioneer.web.book.mapper.BookMapper;
import com.pioneer.web.book.mapper.CategoryMapper;
import com.pioneer.web.book.service.ICategoryService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
* @author aom-star@outlook.com
* @description 针对表【category】的数据库操作Service实现
* @createDate 2025-05-18 11:20:55
*/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
    implements ICategoryService {

    @Resource
    private BookMapper bookMapper;

    @Override
    public boolean deleteById(Long categoryId) {
        Book book = new Book();
        book.setCategoryId(categoryId);
        LambdaQueryWrapper<Book> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Book::getCategoryId, categoryId);
        if (!bookMapper.selectList(queryWrapper).isEmpty()) {
            throw new RuntimeException("该分类下有图书，不能删除");
        }
        return removeById(categoryId);
    }
}




